<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改站点管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-astSite-edit" th:object="${astSite}">
            <input name="siteId" th:field="*{siteId}" type="hidden">
            <input type="hidden" id="imgList" name="imgList" th:field="*{imgList}">

            <div class="form-group">    
                <label class="col-sm-3 control-label">上级站点：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
                        <input class="form-control" type="text" onclick="selectAstSiteTree()" id="treeName" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">站点名称：</label>
                <div class="col-sm-8">
                    <input name="siteName" th:field="*{siteName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">站点编号：</label>
                <div class="col-sm-8">
                    <input name="siteNumber" th:field="*{siteNumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">负责人：</label>
                <div class="col-sm-8">
                    <input name="siteLeader" th:field="*{siteLeader}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="sitePhone" th:field="*{sitePhone}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">详细地点：</label>
                <div class="col-sm-8">
                    <input name="siteAddress" th:field="*{siteAddress}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">经纬度：</label>
                <div class="col-sm-8">
                    <input name="siteJingwei" th:field="*{siteJingwei}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">站点状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('ast_site_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="font-noraml">站点图片：</label>
                <div class="file-loading">
                    <input id="multipleFile" name="files" type="file" multiple>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remaek" class="form-control">[[*{remaek}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">显示顺序：</label>
                <div class="col-sm-8">
                    <input name="orderNum" th:field="*{orderNum}" class="form-control" type="number">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/astSite";
        $("#form-astSite-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-astSite-edit').serialize());
            }
        }

        /*站点管理-编辑-选择父站点管理树*/
        function selectAstSiteTree() {
            var options = {
                title: '站点管理选择',
                width: "380",
                url: prefix + "/selectAstSiteTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        var imgVal = $("#imgList").val()
        if(imgVal){
            imgVal = imgVal.split(",")
        }
        $("#multipleFile").fileinput({
            uploadUrl: ctx + 'common/uploads',
            uploadAsync: false,
            initialPreviewAsData: true,
            initialPreview: imgVal,
            // initialPreviewConfig:[{key:0,url:"http://localhost/profile/upload/2024/07/25/3_20240725160544A009.jpg"},{key:1,url:"http://localhost/profile/upload/2024/07/25/3_20240725160544A009.jpg"}]
        }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
            var rsp = data.response;
            var imgList = $("#imgList").val()
            if(imgList){
                imgList = imgList+","+rsp.urls
                $("#imgList").val(imgList)
            }else{
                $("#imgList").val(rsp.urls)
            }
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')


        }).on('fileclear', function (event, id, index) {
            $("#imgList").val("")
        })
        $("#multipleFile").fileinput('_initFileActions');


    </script>
</body>
</html>